<?php
class Registry
{
	private static $instance=null;
	private $registry_array;
	public static  function getInstance()
	{
		if(self::$instance===null)
		{
			$class=__CLASS__;
			self::$instance=new $class();
		}
		return self::$instance;
	}
	
	public function __construct()
	{
		if(self::$instance!==null)
		{
			throw new Exception("Registry is created!");
		}
		else 
		{
			$this->registry_array=array();
		}
	}
	
	public function  isRegisted($key)
	{
		if(array_key_exists($key,$this->registry_array))
		{
			return true;
		}
		else 
		{
			return false;
		}
	}
	
	public function set($key,$value,$cover=false)
	{
		if($this->isRegisted($key))
		{
			if($cover)
			{
				$this->registry_array[$key]=$value;
				return true;
			}
			else 
			{
				return false;
			}
		}
		else 
		{
			$this->registry_array[$key]=$value;
			return true;
		}
	}
	
	public function get($key)
	{
		if($this->isRegisted($key))
		{
			return $this->registry_array[$key];
		}
		else 
		{
			return null;
		}
	}
	
	
	public  function unRegistry($key)
	{
		if($this->isRegisted($key))
		{
			unset($this->registry_array[$key]);
			return true;
		}
		else 
		{
			return false;
		}
	}
}